{include file="common/header" /}
<div class="x-body">
    <div method="post" class="layui-form from1">
        <div class="layui-form-item">
            <label for="pid" class="layui-form-label">
                <span class="x-red">*</span>所属父级
            </label>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <select id="pid" name="pid">
                        <option value="0">顶级菜单</option>
                        {if($authrules)}
                            {foreach($authrules as $k=>$v)}
                                <option value="{$v.id}">{:str_repeat('— —|',$v.level)}{$v.title}</option>
                            {/foreach}
                        {/if}
                    </select>
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="x-red">*</span>菜单名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="css" class="layui-form-label">
                <span class="x-red">*</span>样式
            </label>
            <div class="layui-input-inline">
                <input type="text" id="css" name="css" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>权限规则
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="开启">
                <input type="radio" name="status" value="1" title="关闭" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>排序</label>
            <div class="layui-input-inline">
                <input type="number" name="sort" autocomplete="off" class="layui-input" min="0" value="50">
            </div>
        </div>


        <div class="layui-form-item">

            <button  class="layui-btn add" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </div>
</div>
<script>





    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            // nikename: function(value){
            //     if(value.length < 5){
            //         return '昵称至少得5个字符啊';
            //     }
            // }
            // ,
            // pass: [/(.+){6,12}$/, '密码必须6到12位']
            // ,repass: function(value){
            //     if($('#L_pass').val()!=$('#L_repass').val()){
            //         return '两次密码不一致';
            //     }
            // }
        });

        // //监听提交return false;
        form.on('submit(add)', function(data){
            var from_data = data.field;
            $.ajax({
                url:"/admin/rules/add",
                type:'post',
                data:from_data,
                success:function (data) {
                    if(data.code == 200){
                        layer.alert("增加成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else {
                        layer.alert(data.msg, {icon: 5});
                    }
                    console.log(data);
                },
                error:function (res) {
                    layer.msg('网络错误',{icon:5});
                }
            });
        });

    });
</script>
{include file="common/footer" /}